package zhengqc.list;

public class LinkedList<E> extends AbstractList<E> {
    private List<E> list;
    public LinkedList(LinkedListType linked_list_type) {
        switch (linked_list_type) {
            case SinglyLinkedList:
                list = new SinglyLinkedList<>();
                break;
            case SinglyLinkedListR:
                list = new SinglyLinkedListR<>();
                break;
            case SinglyLinkedListD:
                list = new SinglyLinkedListD<>();
                break;
            default:
                list = new DoublyLinkedListD<>();
        }
    }
    public LinkedList() {
        this(LinkedListType.DoublyLinkedListD);
    }

    public LinkedList(E[] array, LinkedListType linked_list_type) {
        this(linked_list_type);
        for (E a: array) {
            this.addLast(a);
        }
    }

    public LinkedList(E[] array) {
        this(array, LinkedListType.DoublyLinkedListD);
    }

    @Override
    public int getSize() {
        return list.getSize();
    }

    @Override
    public boolean isEmpty() {
        return list.isEmpty();
    }

    @Override
    public boolean contains(E element) {
        return list.contains(element);
    }

    @Override
    public int indexOf(E element) {
        return list.indexOf(element);
    }

    @Override
    public void clear() {
        list.clear();
    }

    @Override
    public void add(int index, E element) {
        list.add(index, element);
    }

    @Override
    public void addFirst(E element) {
        list.addFirst(element);
    }

    @Override
    public void addLast(E element) {
        list.addLast(element);
    }

    @Override
    public E remove(int index) {
        return list.remove(index);
    }

    @Override
    public E removeFirst() {
        return list.removeFirst();
    }

    @Override
    public E removeLast() {
        return list.removeLast();
    }

    @Override
    public void set(int index, E element) {
        list.set(index, element);
    }

    @Override
    public void setFirst(E element) {
        list.setFirst(element);
    }

    @Override
    public void setLast(E element) {
        list.setLast(element);
    }

    @Override
    public E get(int index) {
        return list.get(index);
    }

    @Override
    public E getFirst() {
        return list.getFirst();
    }

    @Override
    public E getLast() {
        return list.getLast();
    }

    @Override
    public E[] toArray() {
        return list.toArray();
    }

    @Override
    public String toString() {
        return list.toString();
    }
}
